package com.happy016.configuration;

import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自定义Feign配置
 * 1.Feign默认的配置类为:
 *      org.springframework.cloud.netflix.feign.FeignClientsConfiguration.java
 *      定义了编码,解码,所使用的契约等
 * 2.和Ribbon一样,如果不希望这个自定义配置被所有的@FeignClient共享,
 *       该自定义配置不要在主程序@ComponentScan扫描中,即扫描时,过滤该配置
 * 3.通过@FeignClient(name = "SERVICE-USER",configuration= FeignConfiguration.class)来实现自定义配置类
 * @author Linyb
 * @since 2017/9/30 16:42
 */
@Configuration
public class FeignConfiguration {


    /**
     * eg:配置权限拦截规则
     * @author Linyb
     * @since 2017/9/30 16:46
     */
    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor(){
        return new BasicAuthRequestInterceptor("username","password");
    }

    /**
     * feign logger级别
     * @author Linyb
     * @since 2017/10/9 10:46
     */
    @Bean
    Logger.Level feignLoggerLevel(){
        //return Logger.Level.BASIC; //仅记录一些基础的,如请求方法,RUL,响应状态,执行时间
        return Logger.Level.FULL; //记录全部
        //return Logger.Level.NONE;  //不记录任何
        //return Logger.Level.HEADERS; //在BASIC基础上,多记录请求和响应的header
    }
}
